package org.ssssssss.magicapi.controller;

import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.ssssssss.magicapi.vo.ParamVo;
import org.ssssssss.magicapi.vo.Result;

import javax.servlet.http.HttpServletRequest;
import java.util.Arrays;
import java.util.Enumeration;
import java.util.Map;

@RestController
@RequestMapping("test")
public class TestController {

    @PostMapping("/querytest")
    public Result queryTest(@RequestBody ParamVo paramVo,
                            HttpServletRequest request){
        //@RequestBody Map<String,Object> map, @RequestBody ParamVo paramVo
        // @RequestParam(value = "HTBH") String HTBH, @RequestParam(value = "NSRSBH") String NSRSBH,
        // Post的body参数
        System.out.println("name: "+paramVo.getName()+"; age: "+paramVo.getAge());

        System.out.println("------------------------");
        // 请求路径上的参数
        Map<String, String[]> headmap = request.getParameterMap();
        for (Map.Entry<String, String[]> m: headmap.entrySet()) {
            System.out.println(m.getKey()+": "+ Arrays.toString(m.getValue()));
        }

        System.out.println("------------------------");
        // 请求头中的参数
        Enumeration<String> headerNames = request.getHeaderNames();
        while(headerNames.hasMoreElements()){
            String key = headerNames.nextElement();
            System.out.println(key+":  "+request.getHeader(key));
        }

        return Result.success("响应成功");
    }

}
